using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Web;

namespace ProjectCodeS.Models
{ 
    public class ItemTextureRepository : IItemTextureRepository
    {
        ProjectCodeSContext context = new ProjectCodeSContext();

        public IQueryable<ItemTexture> All
        {
            get { return context.ItemTextures; }
        }

        public IQueryable<ItemTexture> AllIncluding(params Expression<Func<ItemTexture, object>>[] includeProperties)
        {
            IQueryable<ItemTexture> query = context.ItemTextures;
            foreach (var includeProperty in includeProperties) {
                query = query.Include(includeProperty);
            }
            return query;
        }

        public ItemTexture Find(int id)
        {
            return context.ItemTextures.Find(id);
        }

        public void InsertOrUpdate(ItemTexture itemtexture)
        {
            if (itemtexture.Id == default(int)) {
                // New entity
                context.ItemTextures.Add(itemtexture);
            } else {
                // Existing entity
                context.Entry(itemtexture).State = EntityState.Modified;
            }
        }

        public void Delete(int id)
        {
            var itemtexture = context.ItemTextures.Find(id);
            context.ItemTextures.Remove(itemtexture);
        }

        public void Save()
        {
            context.SaveChanges();
        }

        public void Dispose() 
        {
            context.Dispose();
        }
    }

    public interface IItemTextureRepository : IDisposable
    {
        IQueryable<ItemTexture> All { get; }
        IQueryable<ItemTexture> AllIncluding(params Expression<Func<ItemTexture, object>>[] includeProperties);
        ItemTexture Find(int id);
        void InsertOrUpdate(ItemTexture itemtexture);
        void Delete(int id);
        void Save();
    }
}